using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace MTRC.ODMS.Web.SOM.Popup
{
    /// <summary>
    /// author:Nearly
    /// </summary>
    public partial class PopupDepartmentCompany : BasePage_SOM
    {
        #region  Page Load and UnLoad
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grdPopSearchStaff.PageSize = this.GridViewPageDefaultSize();

                BindListControl(this.rblStaffType, "EventPersonTypeID", "Description", ODMS.DAL.SOM.CodeSetup.CDEventPersonType.GetEventPersonTypeInSearchWindow(this.LangCode, 0), false);
                this.rblStaffType.Items[0].Selected = true;
                SetLanguage();
            }
        }

        private void SetLanguage()
        {
            this.btnColse.Value = this.GetLabel("COM_Close");

            this.lblStaffType.Text = this.GetLabel("SOM_StaffType", true);
            this.lblDepartment.Text = this.GetLabel("SOM_Department", false);
            this.lblCompany.Text = this.GetLabel("SOM_ContractorCompany", false);
            this.lblAdhoc.Text = this.GetLabel("SOM_Adhoc", false);
            this.lblDepartmentCompany.Text = this.GetLabel("SOM_DepartmentCompany", true);
            this.btnSearch.Value = this.GetLabel("COM_Search");
        }

        private void ChangeLanguage_Click(object sender, System.EventArgs e)
        {
            SetLanguage();
        }

        #endregion

        #region Data Grid Bind

        private void btnSearch_ServerClick(object sender, EventArgs e)
        {
            BindData();
        }

        private void BindData()
        {
            int intStaffType = Convert.ToInt32(this.rblStaffType.SelectedValue);
			string strDepartmentCompany = this.txtDepartmentCompany.Text;

            DataTable dataTable;
            //update by gordon 20151020 U247
            //dataTable = MTRC.ODMS.DAL.SOM.CodeSetup.CdStaffInfo.GetDepartmentCompany(this.LangCode, this.ODMUser.StationID, intStaffType, strDepartmentCompany);
            dataTable = MTRC.ODMS.DAL.SOM.CodeSetup.CdStaffInfo.GetDepartmentCompany(this.LangCode, this.ODMUser.LocationID, intStaffType, strDepartmentCompany);
            DataView dataView = dataTable.DefaultView;
            this.grdPopSearchStaff.GetLabelFunction = new APJ.Web.UI.WebControls.GetLabel(this.GetLabel);
            this.grdPopSearchStaff.DataSource = dataTable.DefaultView;
            this.grdPopSearchStaff.DataBind();
            dataView = null;
            dataTable = null;
        }

        protected void grdPopSearchStaff_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#eaffd9';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
                e.Row.Attributes.Add("OnClick", "setDepartmentCompany('" + DataBinder.Eval(e.Row.DataItem, "DepartmentCompany").ToString() + "', '" + DataBinder.Eval(e.Row.DataItem, "Tel").ToString() + "')");
             }
        }

        private void grdPopSearchStaff_NeedDataBind()
        {

            BindData();
        }

        #endregion

        #region Web Form Designer generated code

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            this.ChangeLanguage += new MTRC.ODMS.Web.BasePage.ChangeLanguageEventHandler(this.ChangeLanguage_Click);
            this.btnSearch.ServerClick += new EventHandler(btnSearch_ServerClick);
            this.grdPopSearchStaff.NeedDataBind += new APJ.Web.UI.WebControls.CommonGridView.NeedDataBindHandler(grdPopSearchStaff_NeedDataBind);
        }

        #endregion
    }
}
